package script
{
	import flash.utils.Dictionary;

	public class Token
	{
		/**
		 * 类型
		 */
		public var type:int;
		
		/**
		 * 值,当类型为常量，则为其值;当类型为ident和操作符或界符，则为其单词;当类型为关键字，则为其单词.
		 */
		public var value:*;
		
		/**
		 * 
		 */
		public var word:String;
		
		/**
		 * 行索引
		 */
		public var lineIndex:int;
		
		/**
		 * 行文本
		 */
		public var lineStr:String;
		
		/**
		 * 关键字列表
		 */
		private static const KEY_WORDS:Vector.<String>=Vector.<String>([
			"as",
			"is",
			"instanceof",
			"extends",
			"in",
			"package",
			"for",
			"var",
			"new",
			"class",
			"function",
			"if",
			"else",
			"while",
			"return",
			"import",
			"public",
			"private",
			"protected",
			"switch",
			"case",
			"break",
			"continue",
			"default",
			"try",
			"catch",
			"finally",
			"each"
		]);
		
		/**
		 * 关键字列表
		 */
		private static const KEY_WORD_DIC:Dictionary=new Dictionary();
		
		{
			KEY_WORD_DIC["as"]=true;
			KEY_WORD_DIC["is"]=true;
			KEY_WORD_DIC["instanceof"]=true;
			KEY_WORD_DIC["extends"]=true;
			KEY_WORD_DIC["in"]=true;
			KEY_WORD_DIC["package"]=true;
			KEY_WORD_DIC["for"]=true;
			KEY_WORD_DIC["var"]=true;
			KEY_WORD_DIC["new"]=true;
			KEY_WORD_DIC["class"]=true;
			KEY_WORD_DIC["function"]=true;
			KEY_WORD_DIC["if"]=true;
			KEY_WORD_DIC["else"]=true;
			KEY_WORD_DIC["while"]=true;
			KEY_WORD_DIC["return"]=true;
			KEY_WORD_DIC["import"]=true;
			KEY_WORD_DIC["public"]=true;
			KEY_WORD_DIC["private"]=true;
			KEY_WORD_DIC["protected"]=true;
			KEY_WORD_DIC["switch"]=true;
			KEY_WORD_DIC["case"]=true;
			KEY_WORD_DIC["break"]=true;
			KEY_WORD_DIC["continue"]=true;
			KEY_WORD_DIC["default"]=true;
			KEY_WORD_DIC["try"]=true;
			KEY_WORD_DIC["catch"]=true;
			KEY_WORD_DIC["finally"]=true;
			KEY_WORD_DIC["each"]=true;
		}
		
		/**
		 * 是否为关键字
		 * @param word
		 * @return 
		 * 
		 */
		public static function isKeyWord(word:String):Boolean{
			return word in KEY_WORD_DIC;
		}
		
		public function Token()
		{
		}
	}
}